package com.xt.xxb.taobao;



import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * @author xt
 * @date 2017年12月12日16:16:49
 */
public class ThreadPoolUtils {
    private static final int DEFAULT_CORE_POOL_SIZE = 1024;
    private static final int DEFAULT_MAX_POOL_SIZE = 1024;
    private static ExecutorService defaultExecutor;

    public static void execute(Runnable command) {
        if (defaultExecutor == null) {
            ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("default executor pool-%d").build();
            defaultExecutor = new ThreadPoolExecutor(DEFAULT_CORE_POOL_SIZE, DEFAULT_MAX_POOL_SIZE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), factory, new ThreadPoolExecutor.AbortPolicy());
        }
        defaultExecutor.execute(command);
    }
}
